<?php
namespace PAT\HomeBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

class HomeController extends Controller
{
    public function indexAction()
    {
    	$liste_product_top_rate = $this->getDoctrine()->getEntityManager()
    		->getRepository('PATProductBundle:Product')
    		->getProductsTopRate(4);
    	
    	$liste_product_top_sales = $this->getDoctrine()->getEntityManager()
    		->getRepository('PATProductBundle:Product')
    		->getProductsTopSales(4);
    	
    	return $this->render('PATHomeBundle::home.html.twig',
    			array("liste_product_top_rate" => $liste_product_top_rate,
    					"liste_product_top_sales" => $liste_product_top_sales));
    }
    
    public function categoryMenuAction()
    {
    	$repository = $this->getDoctrine()->getEntityManager()->getRepository('PATProductBundle:Category');
    	  	
    	$cat_pokematos  = $repository->findBycategoryParent('5');
    	$cat_vetement   = $repository->findBycategoryParent('6');
    	$cat_multimédia = $repository->findBycategoryParent('8');
    	$cat_jouet      = $repository->findBycategoryParent('10');
    	
    	return $this->render('PATHomeBundle::menu.html.twig', array(
    			'cat_pokematos'  => $cat_pokematos,
    			'cat_vetement'   => $cat_vetement,
    			'cat_multimédia' => $cat_multimédia, 
    			'cat_jouet'      => $cat_jouet
    	));
    }
    
    public function contactAction()
    {
        return $this->render('PATHomeBundle::contact.html.twig');
    }
    
    public function lastCommentAction()
    {
    	$em = $this->getDoctrine()->getEntityManager();
        
        $query = $em->createQuery('SELECT c FROM PATCommentBundle:Comment c ORDER BY c.id DESC')
                ->setMaxResults(1);
        
        $lastComment = $query->getSingleResult();
    	
    	return $this->render('PATHomeBundle::footer.html.twig', array(
                        'comment'   => $lastComment
    	));
    }
    
}
